<?php
/**********************
**editdevicetypes.php
**Date Created: 4/13/2009
**Copyright 2009 Tomorrow Tech Industries
**Contact: RPITomorrowTech@gmail.com
**********************/

require_once("private/shared/form.inc");
require_once("private/bottom.inc");
require_once("private/device.inc");
require_once("private/top.inc");

function checkForEdit()
{
	//Did we do an all on request?
	if( !isset($_POST[FORM_DEVICE_TYPE_NAME])
		|| !isset($_POST[FORM_DEVICE_TYPE_URL])
		)
	{
		return TT_OK;
	}
	
	//Extract form data
	$name = $_POST[FORM_DEVICE_TYPE_NAME];
	$iconPath = $_POST[FORM_DEVICE_TYPE_URL];
	
	//Setup input argument map
	$args = array('name' => $name, 'iconPath' => $iconPath);
	//Add the device type
	$rc = Device::addDeviceType($deviceTypeId, $args);
	if( TT_FAILED($rc) )
	{
		echo "Failed to add device type: " . Device::getLastError() . "<BR>";
		return $rc;
	}
	
	echo "Device type " . $name . " added successfuly!<BR>";
	echo "<BR /><BR />";
	
	return TT_OK;
}

function displayPage()
{
	top("Edit Device Types");
	
	checkForEdit();
	
	echo "
		Please fill out this form.<br />
		<FORM name=\"DeviceType\" method=\"Post\" action=\"editdevicetypes.php\">
		<h3>Would you like to:<br /></h3>
		Add Device Type (default)<br />
		Delete Device Type (feature not available yet)<br /><br /><br />


		<h3>Name: <input name=\"" . FORM_DEVICE_TYPE_NAME . "\" type=\"text\" size=\"24\" maxlength=\"64\" /></h3><br />
		<h3>URL for icon (64x64 max image): 
		<input name=\"" . FORM_DEVICE_TYPE_URL . "\" type=\"text\" size=\"24\" maxlength=\"255\" /></h3><br />
		<br />
		<br />

		<br /><input name=\"Submit\" type=\"submit\" value=\"Submit\"/>
		 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"adddevice.php\">Cancel</a>
		</h3>
		</form><br />
		<script type=\"text/javascript\" language=\"JavaScript\">
		document.forms['DeviceType'].elements['name'].focus();
		</script>
		";

	bottom();
}

displayPage();

?>
